﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Cosmetic.Logic;

namespace WebApp.Controls
{
    public partial class NewArrivalProduct : System.Web.UI.UserControl
    {
        private ProductManager m_ProductManager = new ProductManager();

        private int m_ShowCount = 5;
        public int ShowCount
        {
            get { return m_ShowCount; }
            set { m_ShowCount = value; }
        }

        private string m_imageSrc = "../imagesWeb/New01.gif";
        public string ImageSrc
        {
            get { return m_imageSrc; }
            set { m_imageSrc = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindProduct();
            }
        }

        private void BindProduct()
        {
            //this.lvProduct.DataSource = this.m_ProductManager.GetAll().OrderByDescending(theProduct => theProduct.CreateTime).Take(ShowCount).ToList();
            //this.lvProduct.DataSource = this.m_ProductManager.GetAll_L().OrderByDescending(theProduct => theProduct.CreateTime).Take(ShowCount).ToList();
            this.lvProduct.DataSource = this.m_ProductManager.GetNewArrivalProductNew();
            this.lvProduct.DataBind();
        }

        protected void lvProduct_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            int i = 1;
            HtmlImage img = e.Item.FindControl("img") as HtmlImage;

            if (img != null)
            {
                img.Src = "../imagesWeb/New0" + (Convert.ToInt16(e.Item.ID.Substring(4)) + 1).ToString() + ".gif"; ;
            }

            Label lbDescription = e.Item.FindControl("lbDescription") as Label;

            if (lbDescription.Text.Length > 10)
            {
                lbDescription.Text = lbDescription.Text.Substring(0,10);
            }

        }
    }
}